/*
通用js
*/
var IS_DEBUG = true; //调试时使用

/*
Array.prototype.isIn=function(p){//检验一个值是否在array中
	var l=this.length;
	for(var i=l-1;i>=0;i--)
		if(p==this[i])	return i; //在这个Array中,返回index
	return -1; //不在这个Array中,返回-1
}//*/

function isArray(obj){return Object.prototype.toString.apply(obj) == '[object Array]';}//判断Object是否为Array

var browser=(function(){//浏览器判断静态类
	var b=navigator.userAgent.toLowerCase();
	return {
	safari:/webkit/.test(b),
	opera:/opera/.test(b),
	ie:/msie/.test(b) && !/opera/.test(b),
	mozilla:/mozilla/.test(b) && !/(compatible|webkit)/.test(b)
};})();

browser.getValidHeight = function(){ //获取网页高度
	return (window.innerHeight) ? window.innerHeight : document.documentElement.offsetHeight;
}

function objectExtend(targetObject, sourceObject, extendProperties){ //类继承方法
	var p;
	for (p in sourceObject.prototype){ //拷贝方法和属性
		targetObject.prototype[p] = sourceObject.prototype[p];
	}
	for (p in extendProperties){ //扩展
		targetObject.prototype[p] = extendProperties[p];
	}
}

Function.prototype.bind = function(obj){
	var t = this;
	return function(){
		return t.apply(obj, arguments);
	}
};

function parseJson(str){
	try{
		return JSON.parse(str);
	}catch(e){
		return str;
	}
}

if (!window.XMLHttpRequest)
var XMLHttpRequest = function(){
	return new ActiveXObject('Microsoft.XMLHTTP');
};

var ajax = { //ajax类
	get: function(url,callback,asynType){
		asynType = (false == asynType) ? false : true;
		(new request(url, callback, null, asynType)).doGet();
	},
	
	post: function(url, data, callback){
		(new request(url, callback, data, true)).doPost(); //没有写同步功能
	}
};

function request(url, callback, data, asynType){
	this.url = url;
	this.callback = callback;
	this.data = data;
	this.asynType = asynType;
	this.xmlRequest = new XMLHttpRequest();
}
request.prototype = {
	init:function(){
		if (this.asynType)	this.xmlRequest.onreadystatechange = this.checkStatus.bind(this); //异步
	},
	
	doGet:function(){
		this.init();
		this.url += (this.url.indexOf('?') > 0 ? '&' : '?') + 'r=' + Math.random();
		this.xmlRequest.open('GET', this.url, this.asynType);
		this.xmlRequest.send(null);
		if(false == this.asynType){ // 同步
			if (this.isSuccess()){
				return this.callback(this.xmlRequest.responseText);
			}
		}
	},
	
	doPost:function(){//执行post方法
		this.init();
		this.xmlRequest.open('POST', this.url, this.asynType);
		this.xmlRequest.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		this.xmlRequest.send(this.data);
	},
	
	checkStatus:function(){
		if(4==this.xmlRequest.readyState){
			if(true==this.isSuccess())
				this.callback(this.xmlRequest.responseText);
			else
				debug('url:'+this.url+' data:'+this.data+' errorCode:'+this.xmlRequest.status+'msg:'+this.xmlRequest.responseText);
		}
	},

	isSuccess:function(){
		return this.xmlRequest.status < 300;
	}
};

function postParam(jsonObj) { //Ajax Post的时候相当于数据打包
	return JSON.stringify(jsonObj);
}

function die(obj){
	for (p in obj)	obj[p] = null;
	obj = null;
}

function getPosition(){ //取得对象相对另一个对象的位置
	var domNode = arguments[0];
	var parentDiv = arguments[1] || document.body;
	var posTop = 0;
	var posLeft = 0;
	while (domNode != parentDiv){
		posTop += domNode.offsetTop;
		posLeft += domNode.offsetLeft;
		domNode = domNode.offsetParent;
	}
	return [posTop, posLeft];
}

var dom = {//dom节点操作静态类
	fix: {'class':'className','colspan':'colSpan','rowspan':'rowSpan'},
	newNode: function(){
		var tmpObj = document.createElement(arguments[0]);
		if (arguments[1]){
			var properties = arguments[1], tmpPro;
			for (pro in properties){
				tmpPro=this.fix[pro] || pro;
				tmpObj[tmpPro]=properties[pro];
			}
		}
		if (arguments[2])	arguments[2].appendChild(tmpObj);
		return tmpObj;
	},

	makeHtml: function(childs){ //批量生成DOM  childs的格式如['div' ,{'className':'test','id':'testDiv'}, 可选参数] 可选参数包括:dom, 'string' ,childs
		var childsLen = childs.length;
		var tmpNode = this.newNode(childs[0], childs[1]);
		var tmpChild;
		if (2 == childsLen)	return tmpNode; //如果没有可选参数,结束
		for (var i=2; i<childsLen; i++){
			tmpChild = childs[i];
			if (true == isArray(tmpChild))
				tmpNode.appendChild(this.makeHtml(tmpChild)); //如果是Array, 递归make
			else if ('string' == typeof(tmpChild) || 'number' == typeof(tmpChild))
				tmpNode.innerHTML += tmpChild; //如果是string或者number,直接加到innerHTML
			else{
				try{
					tmpNode.appendChild(tmpChild); //试试看是不是Dom
				}catch(e){
					if (IS_DEBUG)	alert('出错了:' + childs[0]);
				}
			}
		}
		
		return tmpNode;
	},

	appendNodes: function(rootNode){
		for (var i = 1, l = arguments.length; i < l; i++){
			rootNode.appendChild(arguments[i]);
		}
	},

	removeEvent: function(rootNode){
		var nodes = rootNode.childNodes;
		for(var i=nodes.length-1; i>=0; i--){
			if (nodes[i].nodeType!=1)	continue; 
			if (nodes[i].childNodes.length>0) //有子节点
				this.removeEvent(nodes[i]);
			else
				eve.stopAllObserve(nodes[i]); //删除绑定事件
		}
		eve.stopAllObserve(rootNode);
	},

	removeNodes: function(rootNode){
		this.removeEvent(rootNode); //首先判断子节点是否绑定有事件
		this.removeChilds(rootNode);
		rootNode = null;
		if (browser.ie)	CollectGarbage();
	},

	removeChilds: function(rootNode){ //删除节点
		var nodes = rootNode.childNodes;
		for(var i = nodes.length-1; i >= 0; i--){
			if (nodes[i].nodeType != 1)	continue;
			if (nodes[i].childNodes.length > 0)
				this.removeChilds(nodes[i]);
			else{
				try{
					rootNode.removeChild(nodes[i]);
					nodes[i] = null;
				}catch(e){}
			}
		}
		try{
			rootNode.parentNode.removeChild(rootNode);
		}catch(e){}
		rootNode = null;
	},

	getById: function(domId){
		return document.getElementById(domId);
	},

	getByName: function(rootNode, domName){
		return rootNode.getElementsByTagName(domName);
	},

	addClass: function(domNode,cssName){
		if (domNode.className.indexOf(cssName)>=0)	return;
		var s = ('' == domNode.className) ? '' : ' '; //如果已经有class了,要先空一格
		domNode.className += s + cssName;
	},
	
	removeClass: function(domNode, cssName){
		var t = domNode.className.indexOf(cssName);
		if (cssName == domNode.className)	return domNode.className = null;
		var s = '';
		if (-1 == t)	return;//没有这个class
		if (0 == t)
			s = cssName + ' ';//第一个class
		else
			s = ' ' + cssName; //不在第一个
		domNode.className = domNode.className.replace(s, '');
	},
	
	show: function(domNode){
		this.removeClass(domNode, 'hide');
	},

	hide: function(domNode){
		this.addClass(domNode, 'hide');
	},

	roleMouseOver: function(domNode, cssName){//鼠标移入和移出两种效果切换
		(new roleMouseOver(domNode, cssName)).init();
	},
	
	roleClick: function(domNode, isOpen){
		(new roleClick(domNode, isOpen)).init();
	},

	roleShow: function(hotArea, effectArea, isShow){
		(new roleShow(hotArea, effectArea, isShow)).init();	
	}
};

var eve = {//事件静态类
	guid: 1, //给每个函数编号
	observe: function(domNode, eveType, handle, obj){
		//debug(domNode.nodeName+' '+domNode.className+' '+eveType + handle.toString()+'<br/><br/>');
		var fn = handle;
		if (!domNode.eve)	domNode.eve = {};
		if (!fn.eveGuid)	fn.eveGuid = this.guid++;
		handle = function(){
			return fn.apply(obj, arguments);
		}
		if (!domNode['eve'][eveType])	domNode['eve'][eveType] = {};
		domNode['eve'][eveType]['guid' + fn.eveGuid] = handle;
		if (browser.ie)
			domNode.attachEvent('on' + eveType, handle);
		else
			domNode.addEventListener(eveType, handle, false);
	},

	stopObserve: function(domNode, eveType, handle){//删除某一绑定事件
		var tmpHandle = [];
		var isHandle = true; //是否移除单个handle
		if (!handle){ //如果没有指定handle,则删除所有的eveType的事件
			for (h in domNode['eve'][eveType]){
				tmpHandle.push(domNode['eve'][eveType][h]);
			}
			isHandle = false;
		}else{
			tmpHandle.push(domNode['eve'][eveType]['guid' + handle.eveGuid]);
		}
		for (var i = tmpHandle.length-1; i>=0; i--){
			if (browser.ie)
				domNode.detachEvent("on" + eveType, tmpHandle[i]);
			else
				domNode.removeEventListener(eveType, tmpHandle[i], false);
		}
		if (true == isHandle)
			delete(domNode['eve'][eveType]['guid' + handle.eveGuid]);
		else
			delete(domNode['eve'][eveType]);
	},

	stopAllObserve: function(domNode){//删除一个dom节点绑定的所有事件
		if (!domNode.eve)	return;//没有绑定事件
		for (t in domNode['eve']){
			this.stopObserve(domNode, t);
		}
	}
};

function roleClick(domNode, cssName){
	this.domNode = domNode;
	this.cssName = cssName;
}

roleClick.prototype = {
	isClick: false,
	init: function(){
		eve.observe(this.domNode, 'click', this.checkStatus, this);
	},
	checkStatus: function(){
		if (true == this.isClick){
			dom.removeClass(this.domNode,this.cssName);
			this.isClick = false;
		}else{
			dom.addClass(this.domNode, this.cssName);
			this.isClick = true;
		}
	}
}

function roleShow(hotArea, effectArea, isShow){
	this.hotArea = hotArea;
	this.effectArea = effectArea;
	this.isShow = isShow;
}
roleShow.prototype = {
	init: function(){
		eve.observe(this.hotArea, 'click', this.checkIsShow, this);
	},
	
	checkIsShow: function(){
		if (true == this.isShow){
			dom.hide(this.effectArea);
			this.isShow = false;
		}else{
			dom.show(this.effectArea);
			this.isShow = true;
		}
	}
};

function roleMouseOver(domNode, cssName){//鼠标移入移出CSS切换类
	this.domNode = domNode;
	this.cssName = cssName;
}
roleMouseOver.prototype = {
	init: function(){
		eve.observe(this.domNode, 'mouseover', this.mouseOver, this);
		eve.observe(this.domNode, 'mouseout', this.mouseOut, this);
	},

	mouseOver: function(){
		dom.addClass(this.domNode, this.cssName);
	},

	mouseOut: function(){
		dom.removeClass(this.domNode, this.cssName);
	}
};

function closeSelect(obj){ //禁止选中
	if (browser.ie)
		eve.observe(obj, 'selectstart', function(){return false;});
	else
		dom.addClass(obj, 'noselect');
}

function openSelect(obj){ //允许选中
	if (browser.ie)
		eve.stopObserve(obj, 'selectstart');
	else
		dom.removeClass(obj, 'noselect');
}

function debug(str){//打印调试函数
	dom.getById('debug').appendChild(dom.makeHtml(['div',{},str + '']));
}

function publicWindow(){ //参数顺序(主体div, 标题, 宽度, 距离左边的位置) 标题和宽度是可选参数
	this.contentDiv = arguments[0];
	this.title = arguments[1] || '系统消息';
	this.width = arguments[2] || 500; //宽度
	this.styleLeft = arguments[3];
}

publicWindow.prototype = {
	height: -1, //窗口高度,-1表示还未知 
	zindex: 1, //层次关系
	canClose: true,//是否可关闭
	canMini: true, //是否可最小化
	canMax: true, //是否可最大化
	canMove: true, //是否可移动
	canResize: true, //是否可以改变窗口大小
	isBlock: false, //是否出现蒙板
	miniWidth: 120, //最小化后的宽度
	minWidth: 100,
	minHeight: 100,
	status: 0, //0正常状态, -1最小化 1最大化
	closeCallBack: function(){}, //关闭窗口时执行的回调函数
	previousWindow: 'NULL', //上一个弹出的窗口,默认为'NULL'而不是null的目前是区分手动定位的窗口
	nextWindow: 'NULL',
	cssNameSpace: 'im_window',//cssNameSpace为CSS命名空间,不同的名字空间控制不同的风格, 默认为'im_window'
	init: function(){
		this.windowDiv = dom.newNode('div', {'class':this.cssNameSpace + ' window_div'}); //除了名字空间外,还要加入imdiv共用的className
		document.body.appendChild(this.windowDiv);
		dom.addClass(this.windowDiv, 'absolute'); //绝对定位
		this.createWindowHtml();//生成窗体html代码
		this.windowDiv.style.top = document.documentElement.scrollTop + 100 + 'px';
		this.windowDiv.style.zIndex = publicWindow.prototype.zindex++;
		if (true == this.isBlock)	this.makeBlock();
		eve.observe(this.windowDiv, 'mousedown', this.setFocus, this); //多个窗口时,当鼠标在某个窗口mousedown,将窗口置顶
		if (true == this.canMax)	eve.observe(this.headDiv, 'dblclick', this.dblClickTitle, this);
		this.setWidth(this.width);
		this.setTitle(this.title);
		this.setIcon(); //设置窗口的最小化、最大化、关闭图标
		this.setPosition(); //设置窗口的位置
	},

	setWidth: function(w){
		this.windowDiv.firstChild.style.width = w + 'px';
	},

	setPosition: function(){ //窗口摆放位置算法
		if (this.styleLeft){ //如果是指定位置的窗口
			this.windowDiv.style.left = this.styleLeft + 'px';
		}else{
			if ('NULL' != this.previousWindow){ //如果有上一个窗口
				if (true == this.checkPosition()){//如果靠着上一个窗口的位置放置不会超出浏览器宽度
					this.windowDiv.style.left = (parseInt(this.previousWindow.windowDiv.style.left) + 30) + 'px';
					this.windowDiv.style.top = (parseInt(this.previousWindow.windowDiv.style.top) + 30) + 'px';
				}else{ //会超出宽度,放到初始位置
					this.setOriginalPosition();
				}
			}else{ //不存在上一个窗口 放在初始位置
				this.setOriginalPosition();
			}
			this.previousWindow = publicWindow.prototype.previousWindow; //上一窗口
			publicWindow.prototype.previousWindow.nextWindow = this; //上一窗口的nextWindow=thiz
			publicWindow.prototype.previousWindow = this; //最后一个窗口
		}
	},
	
	checkPosition: function(){ //判断窗口是否可以挨着上一个窗口放
		if (document.body.clientWidth - parseInt(this.previousWindow.windowDiv.style.left) - 30 < this.windowDiv.clientWidth)	return false; //宽度不够
		var h = browser.getValidHeight(); //取网页高度
		if (h - parseInt(this.previousWindow.windowDiv.style.top) - 30 < this.windowDiv.clientHeight)	return false; //高度不够
		return true;
	},

	setOriginalPosition: function(){
		if (document.body.clientWidth - this.windowDiv.clientWidth){
			this.windowDiv.style.left = parseInt((document.body.clientWidth - this.windowDiv.clientWidth)/2) + 'px';
			this.windowDiv.style.top = '100px';
		}else{
			this.windowDiv.style.left = '0px';
			this.windowDiv.style.top = '0px'
		}
	},
	
	setIcon: function(){
		if (true == this.canClose){//如果可关闭,加入关闭图标
			this.closeIcon = dom.newNode('div', {'class':'icon close'}, this.headDiv);
			dom.roleMouseOver(this.closeIcon, 'close_over');
			eve.observe(this.closeIcon, 'click', this.closeWindow, this);
		}
		if (true == this.canMax){//如果可最大化,加入最大化图标
			this.maxIcon = dom.newNode('div', {'class':'icon max'}, this.headDiv);
			dom.roleMouseOver(this.maxIcon, 'max_over');
			eve.observe(this.maxIcon, 'click', this.maxWindow, this);
		}
		if (true == this.canMini){//如果可最小化,加入最小化图标
			this.miniIcon = dom.newNode('div', {'class':'icon mini'}, this.headDiv);
			dom.roleMouseOver(this.miniIcon, 'mini_over');
			eve.observe(this.miniIcon, 'click', this.miniWindow, this);
		}
		if(true == this.canMax || true == this.canMini){ //加入还原图标
			this.normalIcon = dom.newNode('div', {'class':'icon normal'});
			dom.roleMouseOver(this.normalIcon, 'normal_over');
			eve.observe(this.normalIcon, 'click', this.normalWindow, this);
		}
	},

	makeBlock: function(){ //生成蒙板
		this.block = dom.newNode('div', {'class':'shadow'}, document.body);
		this.block.style.height = document.body.offsetHeight + 'px';
	},

	createWindowHtml: function(){
		this.headDiv=dom.makeHtml(['td', {'class':'top_center'}, ['span', {'class':'title'}]]);
		this.windowBody = dom.makeHtml(//窗口主体内容部分
			['tbody', {},
				['tr', {},
					['td', {'class':'vertical_left'}],
					['td', {'class':'content_td'}],
					['td', {'class':'vertical_right'}]
				]
			]); 
		this.windowDiv.appendChild(dom.makeHtml( 
			['table',{'cellPadding':'0','cellSpacing':'0'},
				['thead', {},
					['tr', {},
						['td', {'class':'corner_left_top'}],
						['td', {'class':'top_line'}],
						['td', {'class':'corner_right_top'}]
					],
					['tr',{'class':'head'},
						['td', {'class':'bar_left'}],
						this.headDiv,
						['td', {'class':'bar_right'}]
					]
				],
				this.windowBody,
				['tfoot',{},
					['tr',{'class':'foot'},
						['td', {'class':'corner_left_foot'}],
						['td', {'class':'foot_center'}],
						['td', {'class':'corner_right_foot'+ (this.canResize) ? ' resize':''}]
					]
				]
			]));
		if (this.canResize){ //设置改变窗体大小的事件
			this.hotAreaTd = []; //热区
			var tds = this.windowDiv.getElementsByTagName('td');
			this.setDrag(tds[0], [1,1,-1,-1], 'nw-resize'); //1:向上移动 1:向左移动 -1:改变窗口高度(反向) -1:改变窗口宽度(反向)    左上角
			this.setDrag(tds[1], [1,0,-1,0], 'n-resize');  //1:向上移动 0:不向左移动 -1:改变窗口高度(反向) 0:不改变窗口宽度        最顶
			this.setDrag(tds[2], [1,0,-1,1], 'ne-resize');  //1:向上移动 0:不向左移动 -1:改变窗口高度(反向) 1:改变窗口宽度(正向)   右上角
			this.setDrag(tds[3], [0,1,0,-1], 'w-resize');  //0:向上不移动 1:向左移动 0:不改变窗口高度 -1:改变窗口宽度(反向)        左边
			this.setDrag(tds[5], [0,0,0,1], 'e-resize');   //                                                               右边
			this.setDrag(tds[6], [0,1,0,-1], 'w-resize');  //                                                               左边
			this.setDrag(tds[8], [0,0,0,1], 'e-resize');   //                                                               右边
			this.setDrag(tds[9], [0,1,1,-1], 'sw-resize');  //                                                              左下角
			this.setDrag(tds[10], [0,0,1,0], 's-resize');  //                                                               左下角
			this.setDrag(tds[11], [0,0,1,1], 'se-resize');  //                                                              左下角
			this.hotAreaTd =[tds[0],tds[1]];
			this.hotAreaTd.push(tds[1], tds[2], tds[3], tds[5], tds[6], tds[8], tds[9], tds[10], tds[11]);
			this.setHotAreaCursor(1);
		}
		if (true == this.canMove)	this.setDrag(this.headDiv, [1,1,0,0], 'default'); //如果这个窗口可以移动,加入拖动事件
		this.windowBody.getElementsByTagName('td')[1].appendChild(this.contentDiv); //内容
	},

	setFocus: function(){ //如果不是最顶层,置顶
		if (-1 == this.status)	this.normalWindow(); //如果是最小化,首先还原窗口
		if (parseInt(this.windowDiv.style.zIndex) + 1 != publicWindow.prototype.zindex)	this.windowDiv.style.zIndex = publicWindow.prototype.zindex++;
	},

	normalWindow: function(){ //还原窗口
		if (-1 == this.status){ //从最小化还原
			document.body.appendChild(this.windowDiv);
			this.reHeight(0);
		//	this.reWidth(0);
			if (this.canClose)	this.headDiv.appendChild(this.closeIcon); //还原关闭图标,不能和下边还原最小化图标位置调换	
		}
		dom.removeClass(this.windowDiv, 'full_size');
		dom.removeClass(this.normalIcon, 'normal_over'); //手动去掉mouseover的效果
		dom.show(this.windowBody); //还原内容
		this.reHeight(this.height - this.contentDiv.offsetHeight);
		dom.addClass(this.windowDiv, 'absolute'); //还原绝对定位方式
		this.setWidth(this.width);
		this.headDiv.removeChild(this.normalIcon);
		if (this.canMini)	this.headDiv.appendChild(this.miniIcon);
		if (this.canMax)	this.headDiv.insertBefore(this.maxIcon, this.headDiv.lastChild);
		this.contentDiv.style.height = this.height + 'px';
		this.setTitle(this.title);
		if (this.canMove)	this.windowDiv.canMove = true;
		this.status = 0;
		if (this.canResize)	this.setHotAreaCursor(1);
	},

	closeWindow: function(){
		/*if ('NULL' != this.nextWindow)	debug('关闭前下一窗口:'+this.nextWindow.title);
		if ('NULL' != this.previousWindow)	debug('关闭前上一窗口:'+this.previousWindow.title);
		if ('NULL' != publicWindow.prototype.previousWindow)	debug('关闭前最后窗口:'+publicWindow.prototype.previousWindow.title);//*/
		this.closeCallBack(); //先执行回调函数
		if (this.canMini)	this.headDiv.appendChild(this.miniIcon); //把所有的icon 都 append上去,再removeNodes,防止内存泄漏
		if (this.canMax)	this.headDiv.appendChild(this.maxIcon);
		if (this.canMini || this.canMax)	this.headDiv.appendChild(this.normalIcon);
		if (this == publicWindow.prototype.previousWindow){ //最后一个窗口
			publicWindow.prototype.previousWindow = this.previousWindow; //如果关闭的窗口是最后打开的窗口
			if ('NULL' != this.previousWindow)	this.previousWindow.nextWindow = 'NULL';
		}else if ('NULL' != this.previousWindow && 'NULL' != this.nextWindow){ //中间窗口
			this.previousWindow.nextWindow = this.nextWindow; //将上一窗口的nextWindow 改为自己的nextWindow
			this.nextWindow.previousWindow = this.previousWindow;
		}else{
			this.nextWindow.previousWindow = 'NULL'; //这是第一个窗口
		}
		this.previousWindow = null;
		this.nextWindow = null;
		//debug('关闭后最后窗口:'+(publicWindow.prototype.previousWindow.title || 'NULL'));
		dom.removeNodes(this.windowDiv);
		this.previousWindow = null;
		if (this.isBlock)	dom.removeNodes(this.block); //移除阴影
		die(this);
	},
	
	getHeight: function(){ //获取窗体高度
		this.height = this.contentDiv.offsetHeight;
	},

	miniWindow: function(){
		if (-1 == this.height)	this.getHeight();  //如果窗口高度未知,首先获取窗体高度
		this.headDiv.insertBefore(this.normalIcon, this.miniIcon);
		dom.removeClass(this.miniIcon, 'mini_over'); //手动去掉mouseover的效果
		this.headDiv.removeChild(this.miniIcon); //隐藏最小化图标
		if (this.canMax)	if (this.maxIcon.parentNode)	this.headDiv.removeChild(this.maxIcon); //如果最大化图标已经加载
		if (this.canClose)	this.headDiv.removeChild(this.closeIcon);
		if (!publicWindow.prototype.miniBar)	this.makeMiniBar(); //如果没有最小化窗口摆放栏,成生
		dom.hide(this.windowBody); //隐藏主体部分
		dom.removeClass(this.windowDiv, 'absolute'); //取消绝对定位
		publicWindow.prototype.miniBar.appendChild(this.windowDiv); //将缩小后的窗口加入到最小化栏
		this.setWidth(this.miniWidth); //设置宽度为最小化宽度
		this.setTitle(this.title);
		this.status = -1;
		if (this.canResize)	this.setHotAreaCursor(0);
	},
	
	setTitle: function(titleStr){
		var icons = this.headDiv.childNodes;
		var iconsWidth = 0; //首先取得icons的宽度
		for (var i = icons.length - 1; i >= 0; i--){
			if (icons[i].nodeName.toLowerCase() != 'div')	continue;
			iconsWidth += icons[i].offsetWidth;
		}
		icons = null;
		this.headDiv.firstChild.innerHTML = titleStr;
		var titleDiv = this.headDiv.firstChild;
		var headWidth = this.headDiv.offsetWidth;
		if (headWidth < iconsWidth + titleDiv.offsetWidth){ //如果 head长度 < 标题长度+icon长度 需要截取标题
			var titleStr = titleDiv.innerHTML; //标题栏文字
			var l = titleStr.length - 1; // 因为要加上'...'
			while (l >= 0){
				this.headDiv.firstChild.innerHTML = titleStr.substr(0, l--) + '<span class="short_point">...</span>'; //每次减去1个字符并加上 ...
				if (headWidth >= iconsWidth + titleDiv.offsetWidth)	break;
			}
		}else
			this.headDiv.firstChild.innerHTML = titleStr;
	},

	flashTitle: function(str, num){
		if (1 != this.status){ //如果是最小化或者当窗口不是最前位置的时候闪屏
			if (parseInt(this.windowDiv.style.zIndex) + 1 == publicWindow.prototype.zindex){
				this.setTitle(this.title);
				return this.isFlash = false;
			}
		}
		if ('undefined' == typeof(num)){ //没有num参数表示是第一次调用
			if (true == this.isFlash)	return; //如果已经在闪动了,退出
			num = 0;
		}
		if (!this.isFlash)	this.isFlash = true;
		if (0 == num){
			num = 1;
			flashTitle = str;
		}else{
			num = 0;
			flashTitle = this.title;
		}
		this.setTitle(flashTitle);
		setTimeout(function(){this.flashTitle(str, num);}.bind(this),500);
	},

	dblClickTitle: function(){
		if (0 == this.status)
			this.maxWindow();
		else if(1 == this.status)
			this.normalWindow();
	},

	maxWindow: function(){
		this.status = 1; //是否已经最大化
		if (-1 == this.height)	this.getHeight(); //如果窗口高度未知,首先获取窗体高度
		this.setWidth(document.body.clientWidth - 4);
		var h = browser.getValidHeight(); //网页可视高度
		if (publicWindow.prototype.miniBar)	h -= publicWindow.prototype.miniBar.offsetHeight; //最小化栏
		var tmpHeight = h - dom.getByName(this.windowDiv, 'thead')[0].offsetHeight - dom.getByName(this.windowDiv, 'tfoot')[0].offsetHeight - 2;//浏览器可用高度-headDiv高度-foot高度
		this.contentDiv.style.height = tmpHeight + 'px';
		this.reHeight(tmpHeight - this.height);
		dom.addClass(this.windowDiv, 'full_size'); //full_size控制窗口的绝对位置为左上角
		dom.removeClass(this.maxIcon, 'max_over'); //手动去掉mouseover的效果
		this.headDiv.insertBefore(this.normalIcon, this.maxIcon);
		this.headDiv.removeChild(this.maxIcon); //移除最大化图标
		if (this.canResize)	this.setHotAreaCursor(0);
	},

	makeMiniBar: function(){ //生成最小化窗口摆放栏
		publicWindow.prototype.miniBar = dom.newNode('div', {'id':'window_mini_bar'}, document.body);
	},

	setDrag: function(obj, config, curStyle){ //curStyle 是css里的 cursor
		obj.conf = config;
		obj.cur = curStyle;
		eve.observe(obj, 'mousedown', this.initDrag, this);
	},

	setHotAreaCursor: function(isCur){
		for (var i = this.hotAreaTd.length - 1; i >= 0; i--){
			this.hotAreaTd[i].style.cursor = (1 == isCur) ? this.hotAreaTd[i].cur : 'default';	
		}
	},

	initDrag: function(e){
		if (0 != this.status)	return; //不能移动
		if (true == this.isDrag)	return; //还未释放移动事件
		var obj = e.srcElement || e.target;
		while ('td' != obj.tagName.toLowerCase())	obj = obj.parentNode;
		this.isDrag = true;
		var divPosition = this.getPosition();
		closeSelect(document.body); //禁止选取
		eve.observe(window.document, 'mousemove', this.drag, this);
		eve.observe(window.document, 'mouseup', this.stopDrag, this);
		this.moveY = obj.conf[0]; //是否纵向移动
		this.moveX = obj.conf[1]; //是否横向移动
		this.flexY = obj.conf[2]; //纵向伸缩方式
		this.flexX = obj.conf[3]; //横向伸缩方式
		this.divX = divPosition[1];
		this.divY = divPosition[0];
		this.mouseX = e.clientX;
		this.mouseY = e.clientY;
		if (0 != this.flexY){
			this.getHeight(); 
			this.heightShift = 0; //初始化主体内容对象高度的偏移量
		}
	},

	drag: function(e){
		var mx = e.clientX - this.mouseX;
		var my = e.clientY - this.mouseY;
		if (0 != this.flexY){
			var tmpHeight = this.flexY * my + this.height;
			if (tmpHeight > this.minHeight){
				var tmpShift = this.heightShift;
				this.heightShift = this.flexY * my;
				this.reHeight(this.heightShift - tmpShift); //高度改变量
				this.contentDiv.style.height = tmpHeight +'px';
				this.headDiv.offsetWidth;
			}else{
				my = 0;
			}
		}
		if (0 != this.flexX){
			var tmpWidth = this.flexX * mx + this.width;
			if (tmpWidth > this.minWidth){
				this.reWidth(this.flexX * mx);
				this.windowDiv.firstChild.style.width = tmpWidth + 'px';
				this.setTitle(this.title);
			}else{
				mx = 0;
			}
		}
		if (1 == this.moveX && mx != 0){
			this.windowDiv.style.left = this.divX + mx + 'px';
		}
		if (1 == this.moveY && my != 0){
			if (0 < this.divY + my)	this.windowDiv.style.top = this.divY + my + 'px';
		}
	},

	stopDrag: function(){
		eve.stopObserve(window.document, 'mousemove', this.drag);
		eve.stopObserve(window.document, 'mouseup', this.stopDrag);
		openSelect(document.body); //允许选取
		this.width = this.windowDiv.firstChild.offsetWidth;
		if (0 != this.flexY)	this.getHeight();
		this.isDrag = false;
	},

	getPosition: function(){
		return [this.windowDiv.offsetTop,this.windowDiv.offsetLeft];
	},
	
	reWidth: function(){}, //自身不带该方法,由实例化对象重构该方法

	reHeight: function(){}, //自身不带该方法,由实例化对象重构该方法

	initHeightShift: function(){} //
}